package com.team11.server.controller.admin;

import com.team11.server.service.admin.Admin_InsertSInKc_Service;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;

@CrossOrigin
@RestController
@Api(tags = "管理员接口")
public class Admin_InsertSInSk_Controller {
    @Autowired
    private Admin_InsertSInKc_Service admin_insertSInKc_service;
    @ApiOperation("课程选择学生(需要课程id与学号)")
    @PostMapping("/InsertSInKc")
    public String insertSInKc(Integer sKid, @RequestParam(value = "sNumbers" ,required=false)List<String> sNumbers){
        HashMap<String,Object> map=new HashMap<>();
        map.put("sKid",sKid);
        for (String sNumber:sNumbers){
            map.put("sNumber",sNumber);
            if ("1".equals(admin_insertSInKc_service.selHaveS((String) map.get("sNumber")))) {
                if ("1".equals(admin_insertSInKc_service.selSInKc(map))) {
                    if (0==admin_insertSInKc_service.SelHaveSInKq(map)){
                        admin_insertSInKc_service.insertSInSk(map);
                        admin_insertSInKc_service.InsertSInKq(map);
                    }
                }
                else return "学生已在该课程";
            }
            else return "学生不存在";
        }
        return "新增成功";
    }
}
